package com.bwie.controller;

import com.bwie.common.domain.Users;
import com.bwie.common.result.Result;
import com.bwie.common.utils.ImageVerificationCode;
import com.bwie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 手机号登录
     * @param tel
     * @return
     */
    @GetMapping("/login{tel}")
    public Result<Users> login(@PathVariable String tel){
        Users u = userService.login(tel);
        return Result.success(u);
    }

    /**
     * 图片验证码
     * @param stream
     * @throws IOException
     */
//    @GetMapping("/send/{imgCode}")
//    public void imgCode(@RequestBody OutputStream stream) throws IOException {
//        ImageVerificationCode code = new ImageVerificationCode();
//        BufferedImage image = code.getImage();
//        String text = code.getText();
//        redisTemplate.opsForValue().set("code"+text,code,15, TimeUnit.MINUTES);
//        ImageVerificationCode.output(image,stream);
//    }

}
